package com.sort;

import java.util.Arrays;

/**
 * @author yijy
 * @description
 * @create 2021/3/27 下午5:48
 **/
public class QS1 {

    public static void main(String[] args) {
        int[] arr ={2,10,1,6,12,8,0,3,20,11,19,30,27};
        new QS1().quickSort(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }

    public void quickSort(int[] arr, int l, int r){
        if( l < r){
            int middle = adjust(arr, l, r);
            quickSort(arr, 0, middle -1);
            quickSort(arr, middle+1, r);
        }
    }

    public int adjust(int[] arr,int l, int r){
        int temp = arr[l];
        while(l < r){
            while(l<r &&  temp < arr[r]) {
                r --;
            }
            if(l<r) {
                arr[l] = arr[r];
            }
            while(l < r && temp > arr[l]) {
                l ++;
            }
            if( l < r ){
                arr[r] = arr[l];
            }
        }
        arr[l] = temp;
        return l;
    }
}
